# uncompyle6 version 3.9.2
# Python bytecode version base 3.6 (3379)
# Decompiled from: Python 3.10.10 (tags/v3.10.10:aad5f6a, Feb  7 2023, 17:20:36) [MSC v.1929 64 bit (AMD64)]
# Embedded file name: modules\common\MTKLog.py
import os, time
from modules.common.Command_exec import *

def reset_mtklog(sn):
    adb_shell_header = "adb -s %s shell " % sn
    cmdline = "am broadcast -a com.mediatek.mtklogger.ADB_CMD -e cmd_name switch_taglog --ei cmd_target 0 --receiver-foreground  --receiver-include-background"
    execute_cmd(adb_shell_header + cmdline)
    cmdline = "am broadcast -a com.mediatek.mtklogger.ADB_CMD -e cmd_name stop --ei cmd_target 23 --receiver-foreground  --receiver-include-background"
    execute_cmd(adb_shell_header + cmdline)
    time.sleep(5)
    cmdline = "am broadcast -a com.mediatek.mtklogger.ADB_CMD -e cmd_name clear_all_logs --receiver-foreground  --receiver-include-background"
    execute_cmd(adb_shell_header + cmdline)
    time.sleep(5)
    cmdline = "rm -rf /sdcard/mtklog/"
    execute_cmd(adb_shell_header + cmdline)
    cmdline = "rm -rf /sdcard/debuglogger/"
    execute_cmd(adb_shell_header + cmdline)
    time.sleep(5)
    cmdline = "am broadcast -a com.mediatek.mtklogger.ADB_CMD -e cmd_name start --ei cmd_target 1 --receiver-foreground  --receiver-include-background"
    execute_cmd(adb_shell_header + cmdline)
    cmdline = "am broadcast -a com.mediatek.mtklogger.ADB_CMD -e cmd_name switch_taglog --ei cmd_target 1 --receiver-foreground  --receiver-include-background"
    execute_cmd(adb_shell_header + cmdline)
    time.sleep(5)


def pull_mtklog(sn, path):
    adb_pull_cmdline = "adb -s %s pull /sdcard/mtklog %s" % (sn, path)
    execute_cmd(adb_pull_cmdline, timeout=900)
    adb_pull_cmdline = "adb -s %s pull /sdcard/debuglogger %s" % (sn, path)
    execute_cmd(adb_pull_cmdline, timeout=900)


def close_mtklog(sn):
    adb_shell_header = "adb -s %s shell " % sn
    cmdline = "am broadcast -a com.mediatek.mtklogger.ADB_CMD -e cmd_name switch_taglog --ei cmd_target 0 --receiver-foreground  --receiver-include-background"
    execute_cmd(adb_shell_header + cmdline)
    cmdline = "am broadcast -a com.mediatek.mtklogger.ADB_CMD -e cmd_name stop --ei cmd_target 23 --receiver-foreground  --receiver-include-background"
    execute_cmd(adb_shell_header + cmdline)
